package fr.istic.linkedcv.client.presentation.views.impl;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

import fr.istic.linkedcv.client.PersonneCli;
import fr.istic.linkedcv.client.presentation.Personne;
import fr.istic.linkedcv.client.presentation.impl.UiImpl;
import fr.istic.linkedcv.client.presentation.views.View;
import fr.istic.linkedcv.client.services.PersonneService;
import fr.istic.linkedcv.client.services.PersonneServiceAsync;

public class ListePersonnesCli extends View {
	private final PersonneServiceAsync personneServiceAsync = GWT.create(PersonneService.class);
	
	private VerticalPanel vPanel;

	public ListePersonnesCli(UiImpl ui) {
		super(ui);
	}

	@Override
	public Widget getWidget() {
		// TODO Auto-generated method stub
		return vPanel;
	}

	@Override
	public void build() {
		vPanel = new VerticalPanel();
		vPanel.addStyleName("lists");
		vPanel.setWidth("220px");
		personneServiceAsync.getListePersonnes(new AsyncCallback<List<PersonneCli>>() {

					@Override
					public void onSuccess(List<PersonneCli> personnes) {
						if(personnes.size()>0){
							for (PersonneCli personne : personnes) {
								PersonneCli currentPersonne = ui.getControle().getPersonneCli();
								vPanel.add(new Personne(currentPersonne, personne, ui));
							}
						}else{
							vPanel.add(new HTML("Personne d'autre que vous n'est inscrit."));
						}
					}

					@Override
					public void onFailure(Throwable caught) {
						Window.alert("failure");

					}
				});

	}

	
}
